class Solution
{
public:
    int countTriples(int n)
    {
        int n2 = n * n;
        int count = 0;
        for (int a = 1; a < n; ++a)
        {
            for (int b = a + 1; b <= n; ++b)
            {
                int squareSum = a * a + b * b;
                if (squareSum > n2)
                {
                    continue;
                }
                int approxRoot = static_cast<int>(floor(sqrt(squareSum + 1)));
                if (approxRoot * approxRoot == squareSum)
                {
                    ++count;
                }
            }
        }
        return 2 * count;
    }
};